package problems;

import java.util.ArrayList;
import java.util.List;

import lib.MathLib;

import org.junit.Ignore;

@Ignore //because the two non-threaded version are faster and/or smarter
public class Euler012Threaded extends AbstractThreadedEuler {
	
	protected final List<Number> answers = new ArrayList<Number>();
	
	protected long getStartValue() {
		return 1;
	}

	protected Number getFinalAnswer() {
		return MathLib.getSmallest(answers);
	}
	
	protected void doCalculation(long forValue) {
		long triangleNumber = MathLib.getPolygonalNumber(forValue,3).longValue();
		long divisors = MathLib.getNumDivisors(triangleNumber);
		if (divisors > 500) {
			synchronized(answers) {
				answers.add(triangleNumber);
			}
		}
	}

	@Override
	protected Number getCorrectAnswer() {
		return 76576500L;
	}

	@Override
	protected boolean continueCalculating() {
		return answers.isEmpty();
	}
}
